/*
 * @Author: 谢小康 2170673706@qq.com
 * @Date: 2023-12-28 09:25:14
 * @LastEditors: 谢小康 2170673706@qq.com
 * @LastEditTime: 2024-01-04 09:05:18
 * @FilePath: \My-bolg\server\model\photo.js
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
const { DataTypes } = require("sequelize")
const { Sequelize } = require("sequelize")
var moment = require("moment")
const sq = require('./db.js')

const Photo = sq.define(
    "photo",
    {
      album_id: {
        type: DataTypes.INTEGER,
        require: true,
        comment: "相册 id 属于哪个相册",
      },
      url: {
        type: DataTypes.STRING(555),
        require: true,
        comment: "图片地址",
      },
      status: {
        type: DataTypes.INTEGER,
        require: true,
        defaultValue: 1,
        comment: "状态 1 正常 2 回收站",
      },
      createdAt: {
        type: Sequelize.DATE,
        get() {
          return moment(this.getDataValue("createdAt")).format("YYYY-MM-DD HH:mm:ss")
        },
      },
      updatedAt: {
        type: Sequelize.DATE,
        get() {
          return moment(this.getDataValue("updatedAt")).format("YYYY-MM-DD HH:mm:ss")
        },
      },
    },
    {
      freezeTableName: true, // 强制表名不转复数
    }
)
/* Photo.sync({ force: true }) */
module.exports = Photo